IP Packet Processing Example
Packet object provides get/set access to packet data
/* process an IP packet */
void input(Packet pkt) {
  int hlen = pkt.getByte(0) & 0x4;
  int type = pkt.getByte(9);
  int src_ip = pkt.getInt(12);
  if (pkt.cksum(0, hlen) != 0) {
    return;
  }
  if (type == 6) {
    pkt.shiftHeader(20); // strip IP header
    Tcp.input(pkt, src_ip);
  }
}

Return to Tracks